package com.hk.admin.common.dto.system.user;

import com.hk.admin.common.constant.GlobalEnum;
import com.hk.admin.common.model.system.UserModel;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
public class UserDTO {

    private Long id;

    private String phoneNumber;

    private String userName;

    private String headPictureUrl;          // 头像
    private String headPictureBase64;      // 头像

    private Integer accountType;       // 帐号类型，0:平台，1：XXX，2：XXX，...

    private Integer accountStatus;     // 帐号状态，0：可用，1：不可用

    private Date createTime;        // 创建时间

    private Integer areaId;         // 区域
    private String areaName;
    private String address;

    private List<String> roleNames = new ArrayList<>();
    private List<Long> roleIds = new ArrayList<>();

    public UserDTO() {
    }

    public UserDTO(UserModel model) {
        this.id = model.getId();
        this.phoneNumber = model.getPhoneNumber();
        this.userName = model.getUserName();
        this.headPictureUrl = model.getHeadPictureUrl();
        this.accountType = model.getAccountType();
        this.accountStatus = model.getAccountStatus();
        this.createTime = model.getCreateTime();
        this.areaId = model.getAreaId();
        this.areaName = model.getAreaName();
        this.address = model.getAddress();
    }

    public void fitRoles(UserModel model) {
        model.getRoles().forEach(e -> {
            if (!e.alreadyDeleted()) {
                this.roleNames.add(e.getRoleName());
                this.getRoleIds().add(e.getId());
            }
        });
    }

}
